﻿namespace NGridDrawer.Draw
{
    /// <LastUpdate author="Blaise Braye" Date="15/06/2008 17:03"/>
    /// <summary>
    /// Provide an indexed mapping for columns and rows of a grid of data
    /// </summary>
    public class GridMapping
    {
        /// <summary>
        /// 	<para>Initializes an instance of the <see cref="GridMapping"/> class.</para>
        /// </summary>
        /// <param name="rowsMap">
        /// Contains an ordered table of interesting rows indexes of a source grid of data
        /// </param>
        /// <param name="columnsMap">
        /// Contains an ordered table of interesting columns indexes of a source grid of data
        /// </param>
        public GridMapping(int[] rowsMap, int[] columnsMap)
        {
            this.rowsMap = rowsMap;
            this.columnsMap = columnsMap;
        }

        /// <summary>
        /// Contains an ordered table of interesting rows indexes of a source grid of data
        /// </summary>
        /// <value>Auto implemented property</value>
        private int[] rowsMap { get; set; }

        /// <summary>
        /// Contains an ordered table of interesting columns indexes of a source grid of data
        /// </summary>
        /// <value>Auto implemented property</value>
        private int[] columnsMap { get; set; }

        /// <summary>
        /// Gets the total number of rows mapped
        /// </summary>
        public int RowCount
        {
            get { return rowsMap.Length; }
        }


        /// <summary>
        /// Gets the total number of columns mapped
        /// </summary>
        public int ColumnCount
        {
            get { return columnsMap.Length; }
        }

        /// <summary>
        /// Returns the source grid row index 
        /// which is stored in the <paramref name="rowKey"/> position of the rows mapping
        /// </summary>
        /// <param name="rowKey">
        /// </param>
        /// <returns>
        /// </returns>
        public int RowIndex(int rowKey)
        {
            return rowsMap[rowKey];
        }

        /// <summary>
        /// Returns the source grid column index 
        /// which is stored in the <paramref name="columnKey"/> position of the columns mapping
        /// </summary>
        /// <param name="columnKey">
        /// </param>
        /// <returns>
        /// </returns>
        public int ColumnIndex(int columnKey)
        {
            return columnsMap[columnKey];
        }
    }
}